package com.hydeng.house.filter;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

/**
 * Description:
 *
 * @author: hydeng
 * @since: 2018-03-06
 */
@Configuration
public class FilterBeanConfig {

    /**
     * 配置一个自定义的 Filter
     * 1.构造filter
     * 2.配置拦截的路径
     * 3.利用FilterRegistretionBean进行包装
     *
     * @return
     */
    @Bean
    public FilterRegistrationBean loggerFilter() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        filterRegistrationBean.setFilter(new LoggerFilter());
        List<String> urlList = new ArrayList<String>();
        urlList.add("*");
        filterRegistrationBean.setUrlPatterns(urlList);
        return filterRegistrationBean;
    }
}
